/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author Hans
 */
public class CommissionWare {

    private Seller seller;
    private String name;
    private String category;
    private ArrayList<PriceHistory> prices;
    private final static double COMMISION = 0.20;
    private long dateIn;
    private long dateOut;

    /**
     *
     * @param seller
     * @param name
     * @param category
     * @param dateIn date in format (dd-mm-yyyy)
     * @param price
     */
    public CommissionWare(Seller seller, String name, String category, long dateIn, int price) {
        this.prices = new ArrayList<>();
        this.seller = seller;
        this.name = name;
        this.category = category;
        this.dateIn = dateIn;
        this.dateOut = 0;
        this.prices.add(new PriceHistory(price, this.dateIn));
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public void setNewPrice(PriceHistory price) {
        prices.add(price);
    }

    public void setNewPrice(int price) {
        PriceHistory ph = new PriceHistory(price, System.currentTimeMillis());
        prices.add(ph);
    }

    public ArrayList<PriceHistory> getPriceHistory() {
        return prices;
    }

    public int getCurrentPrice() {
        PriceHistory price = prices.get(prices.size() - 1);
        return price.getPrice();
    }

    public int getShelfTime() {
        int days = 0;
        return days;
    }

    public int getCommissionAmount() {
        double val = COMMISION * (double) (prices.get(prices.size() - 1).getPrice());
        int amount = (int) val;
        return amount;
    }

    public Seller getSeller() {
        return seller;
    }

    public void setSeller(Seller seller) {
        this.seller = seller;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDateIn() {
        return new Date(dateIn);
    }

    public void setDateIn(long dateIn) {
        this.dateIn = dateIn;
    }

    public Date getDateOut() {
        Date d = null;
        if (dateOut != 0) {
            d = new Date(dateOut);
        }
        return d;
    }

    public void setDateOut(long dateOut) {
        this.dateOut = dateOut;
    }

    public boolean isUnsold() {
        return dateOut == 0;
    }
}
